package org.example.observer.improve;

import java.util.ArrayList;

/**
 * @author wangbin
 * @date 2024/4/19
 * @vesion 1.0
 */
public class WeatherData implements Subject{

    private float temerature;
    private float pressure;
    private float humidity;
    private ArrayList<Observerstr> observerstrs;

    public WeatherData() {
        observerstrs =new ArrayList<>();
    }

    public float getTemerature() {
        return temerature;
    }

    public void setTemerature(float temerature) {
        this.temerature = temerature;
    }

    public float getPressure() {
        return pressure;
    }

    public void setPressure(float pressure) {
        this.pressure = pressure;
    }

    public float getHumidity() {
        return humidity;
    }

    public void setHumidity(float humidity) {
        this.humidity = humidity;
    }


    @Override
    public void registerObserver(Observerstr o) {
        observerstrs.add(o);
    }

    @Override
    public void removeObserver(Observerstr o) {
        observerstrs.remove(o);
    }

    @Override
    public void notifyObservers() {
        for (Observerstr observerstr1 : observerstrs) {
            observerstr1.update(temerature,pressure,humidity);
        }
    }
}
